package com.example.my.agiftthat.ui.shop;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.my.agiftthat.R;
import com.example.my.agiftthat.helper.RecyclerViewAdapterHelper;
import com.example.my.agiftthat.ui.shop.intentactivity.IntentActivitys;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by My on 2016/12/23.
 */

public class ItemAdapter extends RecyclerViewAdapterHelper<ShopBean.DataBean.ItemsBeanX.ItemsBean> {

    public ItemAdapter(Context context, List<ShopBean.DataBean.ItemsBeanX.ItemsBean> list) {
        super(context, list);

    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_item_shop, parent, false);

        return new ViewHolder(view);

    }
//    holder.itemView.setOnClickListener(new View.OnClickListener() {
//        @Override
//        public void onClick(View v) {
//
//        }
//    });

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, IntentActivitys.class);
                context.startActivity(intent);
            }
        });
        if (holder instanceof ViewHolder) {
            ((ViewHolder) holder).itemText1.setText(list.get(position).getShort_description());
            ((ViewHolder) holder).itemText2.setText("￥ " + list.get(position).getSkus().get(0).getPrice());
            Glide.with(context).load(list.get(position).getCover_image_url()).into(((ViewHolder) holder).itemImage);
        }

    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.item_image)
        ImageView itemImage;
        @Bind(R.id.item_text1)
        TextView itemText1;
        @Bind(R.id.item_text2)
        TextView itemText2;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
